//
//  XDBaseViewController.m
//  HengHuaSupervision
//
//  Created by XD-XY on 3/20/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "XDBaseViewController.h"
#import "XDHeader.h"
#import "XDTools.h"
#import "SumitViewController.h"
//#import "UserInfo.h"

@interface XDBaseViewController ()

@end

@implementation XDBaseViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    self.navigationController.navigationBarHidden =YES;

    if (IOS7){
        self.navigationBarView = [[UIView alloc] initWithFrame:CGRectMake(0, mUI_Status_Bar_Height, mUI_Screen_Height, mUI_Navigation_Bar_Height)];
        _navigationBarBg = [[UIImageView alloc] init];
        _navigationBarBg.frame = CGRectMake(0, -mUI_Status_Bar_Height, mUI_Screen_Height, mUI_Navigation_Bar_Height+mUI_Status_Bar_Height);
        _navigationBarBg.image = mNav_Bg_Img_Ios7;
        [_navigationBarView addSubview:_navigationBarBg];
        [self.view addSubview:_navigationBarView];
    }else{
        self.navigationBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, mUI_Screen_Height, mUI_Navigation_Bar_Height)];
        _navigationBarBg = [[UIImageView alloc] init];
        _navigationBarBg.frame = _navigationBarView.bounds;
        _navigationBarBg.image = mNav_Bg_Img;
        [_navigationBarView addSubview:_navigationBarBg];
        [self.view addSubview:_navigationBarView];
    }
    
    self.contentView = [UIView initView:CGRectMake(0,height_y(_navigationBarView), mUI_Screen_Height, mUI_Screen_Width-(height_y(_navigationBarView))) bgcolor:mApp_Bg_color];
    [self.view addSubview:_contentView];

    [self initXDbaseViews];
    [self initConstantArray];

}
-(void)initXDbaseViews
{
//    _backBtn.hidden =NO;
//    _backBtn.frame = CGRectMake(12,(mUI_Navigation_Bar_Height-mNav_Back_Img.size.height)/2.0f, mNav_Back_Img.size.width, mNav_Back_Img.size.height);
//    _userBtn.frame = CGRectMake(width_x(_backBtn)+22.5,(mUI_Navigation_Bar_Height-mNav_Userhead_Img.size.height)/2.0f, mNav_Userhead_Img.size.width, mNav_Userhead_Img.size.height);
//    _userLabel.frame = CGRectMake(width_x(_userBtn)+7, 0,100, mUI_Navigation_Bar_Height);
    
    
    //自定义标题栏
    self.titleLabel = [UILabel initLabel:mNav_TitleLabel_Frame textFont:mNav_Title_Font textColor:mNav_title_Color textAlignment:NSTextAlignmentCenter];
    [_navigationBarView addSubview:_titleLabel];
    
    //自定义返回按钮
    self.backBtn = [UIButton initButton:CGRectMake(12,(mUI_Navigation_Bar_Height-mNav_Back_Img.size.height)/2.0f, mNav_Back_Img.size.width, mNav_Back_Img.size.height) btnImage:mNav_Back_Img btnTitle:nil titleColor:nil titleFont:nil];
    [_backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_navigationBarView addSubview:_backBtn];
    
    //自定义头像
    self.userBtn = [UIButton initButton:CGRectMake(width_x(_backBtn)+22.5,(mUI_Navigation_Bar_Height-mNav_Userhead_Img.size.height)/2.0f, mNav_Userhead_Img.size.width, mNav_Userhead_Img.size.height) btnImage:mNav_Userhead_Img btnTitle:nil titleColor:nil titleFont:nil];
    _userBtn.adjustsImageWhenHighlighted = NO;
    [_navigationBarView addSubview:_userBtn];
    
    //自定义用户名标签
    self.userLabel = [UILabel initLabel:CGRectMake(width_x(_userBtn)+7, 0,100, mUI_Navigation_Bar_Height) textFont:mNav_Username_Font textColor:mNav_title_Color textAlignment:NSTextAlignmentLeft];
    [_navigationBarView addSubview:_userLabel];
    
     _userLabel.text = [UserInfo sharedUserInfo].username;
    
    //自定义数据初始化按钮
    self.initlalizeBtn = [UIButton initButton:CGRectMake(1515/2.0f, (mUI_Navigation_Bar_Height-mNav_InitData_Normal_Img.size.height)/2.0f, mNav_InitData_Normal_Img.size.width, mNav_InitData_Normal_Img.size.height) btnNorImage:mNav_InitData_Normal_Img btnPressBtn:mNav_InitData_Highlight_Img btnTitle:nil titleColor:nil titleFont:nil];
    [_initlalizeBtn addTarget:self action:@selector(initlalizeData) forControlEvents:UIControlEventTouchDown];
//    [_navigationBarView addSubview:_initlalizeBtn];
    [_initlalizeBtn setHidden:YES];
    
    //自定义数据初始化标签
    self.initlalizeLabel = [UILabel initLabel:CGRectMake(1613/2.0f,0,80, mUI_Navigation_Bar_Height) textFont:mNav_Username_Font textColor:mNav_title_Color textAlignment:NSTextAlignmentLeft];
//    [_navigationBarView addSubview:_initlalizeLabel];
    _initlalizeLabel.text = @"数据初始化";
    [_initlalizeLabel setHidden:YES];
    
    //自定义未提交按钮
    self.waitSubmitBtn = [UIButton initButton:CGRectMake(1791/2.0f,(mUI_Navigation_Bar_Height-mNav_Waitsumit_Highlight_Img.size.height)/2.0f,mNav_Waitsumit_Normal_Img.size.width, mNav_Waitsumit_Normal_Img.size.height) btnNorImage:mNav_Waitsumit_Normal_Img btnPressBtn:mNav_Waitsumit_Highlight_Img btnTitle:nil titleColor:nil titleFont:nil];
    [_waitSubmitBtn addTarget:self action:@selector(gotoSubmitViewController) forControlEvents:UIControlEventTouchDown];
    [_navigationBarView addSubview:_waitSubmitBtn];
    
    //自定义未提交标签
    self.waitSubmitLabel = [UILabel initLabel:CGRectMake(1886/2.0f, 0,80, mUI_Navigation_Bar_Height) textFont:mNav_Username_Font textColor:mNav_title_Color textAlignment:NSTextAlignmentLeft];
    [_navigationBarView addSubview:_waitSubmitLabel];
    _waitSubmitLabel.text = @"本地提交";
    
    //提醒按钮
    self.remindBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _remindBtn.titleLabel.font = [UIFont systemFontOfSize:11.0];
    [_remindBtn addTarget:self action:@selector(gotoSubmitViewController) forControlEvents:UIControlEventTouchUpInside];
    [_navigationBarView addSubview:_remindBtn];
    
}

//计算提示按钮的坐标
-(void)calculateRemindBtnFrame:(NSString *)titleCount{
    if (IS_NOT_EMPTY(titleCount)){
        if ([titleCount intValue]<10) {
            [self.remindBtn setBackgroundImage:[UIImage imageNamed:@"remind_yuan"] forState:UIControlStateNormal];
            self.remindBtn.frame = CGRectMake(0, 0, 14, 14);
            self.remindBtn.center = CGPointMake(self.waitSubmitBtn.frame.origin.x+30, self.waitSubmitBtn.frame.origin.y+7);
        }else{
            [self.remindBtn setBackgroundImage:[[UIImage imageNamed:@"remind_tuo"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal];
            CGSize textSize = [titleCount sizeWithFont:[UIFont systemFontOfSize:11.0]
                                     constrainedToSize:CGSizeMake(100, 14) lineBreakMode:NSLineBreakByCharWrapping];
            self.remindBtn.frame = CGRectMake(0, 0, textSize.width+4, 14);
            self.remindBtn.center = CGPointMake(self.waitSubmitBtn.frame.origin.x+30, self.waitSubmitBtn.frame.origin.y+7);
            
        }
        [self.remindBtn setTitle:titleCount forState:UIControlStateNormal];
    }else{
        self.remindBtn.frame = CGRectMake(0, 0, 0, 0);
    }
}

//数据全部下载
-(void)initlalizeData
{
    
}

//进入待提交数据页面
-(void)gotoSubmitViewController
{
    SumitViewController * sumitVC = [[SumitViewController alloc] init];
    [self.navigationController pushViewController:sumitVC animated:YES];
}
-(void)pushNewVC:(XDBaseViewController *)sender{
    [self.navigationController pushViewController:sender animated:YES];
}
//返回按钮
-(void)backBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

//控制隐藏返回按钮
-(void)setHiddenBackBtn:(BOOL)ishidden
{
    if (ishidden){
        _backBtn.hidden = YES;
        _userBtn.frame = CGRectMake(12,(mUI_Navigation_Bar_Height-mNav_Userhead_Img.size.height)/2.0f, mNav_Userhead_Img.size.width, mNav_Userhead_Img.size.height);
        _userLabel.frame = CGRectMake(width_x(_userBtn)+18, 0,100, mUI_Navigation_Bar_Height);
    }else{
        _backBtn.hidden =NO;
        _backBtn.frame = CGRectMake(12,(mUI_Navigation_Bar_Height-mNav_Back_Img.size.height)/2.0f, mNav_Back_Img.size.width, mNav_Back_Img.size.height);
        _userBtn.frame = CGRectMake(width_x(_backBtn)+22.5,(mUI_Navigation_Bar_Height-mNav_Userhead_Img.size.height)/2.0f, mNav_Userhead_Img.size.width, mNav_Userhead_Img.size.height);
        _userLabel.frame = CGRectMake(width_x(_userBtn)+7, 0,100, mUI_Navigation_Bar_Height);
    }
}


-(void)initConstantArray
{
    //设备监造首页的表头字段
    self.assert_info_array = [NSArray arrayWithObjects:@"   序号",@"设备编码",@"名称",@"型号",@"生产厂家",@"标签",@"贴标签", nil];
    self.sumit_info_array = [NSArray arrayWithObjects:@"设备编号",@"设备名称",@"标签编号",@"贴签部位",@"扫描地点", @"贴签时间",nil];
    
    self.label_edit_array = [NSArray arrayWithObjects:@"标签编号",@"贴签部位",@"扫描终端",@"扫描位置",@"贴签时间", nil];
    self.press_ifo_array =@[@[@"设备编号",@"设备名称"],@[@"贴标签时间",@"监造人"],@[@"操作人位置",@""],@[@"贴签位置",@""],@[@"备注",@""]];
    self.details_info_array =@[@[@"设备编号",@"设备名称"],@[@"设备型号",@"设备类别"],@[@"生产厂家",@"厂家编号"],@[@"厂家电话",@"负责人"],@[@"厂家地址",@""],@[@"监造单位",@"单位编码"],@[@"监造方式",@"监造人员"],@[@"监造状态",@""],@[@"备注",@""]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
